package com.zrrd.mybatis_02.mapper;

import com.zrrd.mybatis_02.entity.Tea;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title TeaMapper
 * @description 操作Tea实体类和数据库中Tea表映射关系的Mapper接口
 * @create 2024/9/22
 */
public interface TeaMapper {
    //因为TeaMapper是接口，接口里的方法，默认都是使用public abstract修饰的方法

    /**
     * 查询所有
     * @return
     */
    @Select("SELECT * FROM tea")
    List<Tea> selectAll();

    @Select("SELECT * FROM tea")
    List<Tea> selectAll02(RowBounds rowBounds);

    @Select("SELECT * FROM tea LIMIT #{offset},#{limit}")
    List<Tea> selectAll03(@Param("offset") Integer offset, @Param("limit") Integer limit);


    /**
     * 插入
     * @param tea
     * @return
     */
    @Insert("INSERT INTO tea VALUES(#{id},#{teaName},#{teaTypeId},#{ordered},#{description},#{status})")
    Integer add(Tea tea);

    /**
     * 删除
     * @param id
     * @return
     */
    @Delete("DELETE FROM tea WHERE id=#{id}")
    Integer remove(Integer id);

    /**
     * 修改
     * @param tea
     * @return
     */
    @Update("UPDATE tea " +
            "SET teaName=#{teaName},teaTypeId=#{teaTypeId}, ordered=#{ordered}," +
            "description=#{description},status=#{status} " +
            "WHERE id=#{id}")
    Integer edit(Tea tea);

    /**
     * 根据id查询茶叶信息
     * @param id
     * @return
     */
    @Select("SELECT * FROM tea WHERE id=#{id}")
    Tea selectById(Integer id);


}
